Page({
    data: {
      date: '',
      imagePath: ''
    },
    onDateChange(e) {
      this.setData({ date: e.detail.value });
    },
    chooseImage() {
      wx.chooseMedia({
        count: 1,
        mediaType: ['image'],
        sizeType: ['compressed'],
        success: (res) => {
          const file = res.tempFiles[0];
          if (file.size > 5 * 1024 * 1024) {
            wx.showToast({ title: '图片不能大于5MB', icon: 'none' });
            return;
          }
          this.setData({ imagePath: file.tempFilePath });
        }
      });
    },
    onSubmit(e) {
      const { name, desc, location } = e.detail.value;
      if (!name || !desc || !this.data.date || !location) {
        wx.showToast({ title: '请填写必填项', icon: 'none' });
        return;
      }
      // 把数据带到下一页
      wx.navigateTo({
        url: '/pages/create-activity/mycreate',
        success: (res) => {
          res.eventChannel.emit('acceptData', {
            name,
            desc,
            date: this.data.date,
            location,
            imagePath: this.data.imagePath
          });
        }
      });
    }
  });